#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2020/7/9 1:28
# @Author : LZQ
# @Version：V 0.1
# @File : token_verify.py
# @desc :
from flask import request, jsonify, session, g
from __init__ import db, redis_store
from app.utils.token import certify_token, generate_token
from app.utils.status_code import RET
import json
import functools


def verify(view_func):
    @functools.wraps(view_func)
    def wrapper(*args, **kwargs):
        token = request.headers.get("Authorization")
        pwd = str(redis_store.hget(token, "token"))
        if pwd is not None and pwd != 'None':
            is_tagger = certify_token(pwd.split("'")[1], token)
            if is_tagger:
                return view_func(*args, **kwargs)
            else:
                return jsonify({"code":400,"msg":"无效的token"})
        else:
            return jsonify({"code":400,"msg":"无效的token"})

    return wrapper
